// app.js
App({
  globalData: {
    token: '',
    nickName: '',
    avatarUrl: ''
  },
  onLaunch() {
    let that = this;
    wx.cloud.init({
      env: 'prod-9gno6bd407ac56da',
      traceUser: true,
    });

    that.doLogin();
  },
  doLogin: function () {
    const that = this
    // 登录
    wx.login({
      success: res => {
        console.log('kkk====res==', res)
        if (res.code) {
          // 请求接口获取token，保存
          wx.cloud.callContainer({
            config: {
              env: "prod-9gno6bd407ac56da"
            },
            path: "/api/user/login",
            header: {
              "X-WX-SERVICE": "springboot-kd4g"
            },
            method: "POST",
            data: {
              jsCode: res.code,
              nickName: '',
              avatarUrl: ''
            },
            success(res) {
              if (res?.data?.code == 0) {
                that.globalData.token = res?.data?.data?.accessToken || '';
                that.globalData.nickName = res?.data?.data?.nickname || '';
                that.globalData.avatarUrl = res?.data?.data?.avatarUrl || '';
              }
            }
          })
        }
      }
    })
  }
})